package Day015_File类_递归_IO流.demo04_递归练习;

/**
 * @author zhangyan
 * @date 2020/5/6 10:49
 */
public class Test2_递归求阶乘 {
    public static void main(String[] args) {
        /*
        5! = 5*4*3*2*1
        4! = 4*3*2*1
        3! = 3*2*1
        ...
        规律: n的阶乘 = n * (n-1)的阶乘...
      */

        int n = 5;
        System.out.println(jiecheng(5));
    }

    //计算阶乘
    public static int jiecheng(int n) {
        if (n == 1) { //出口
            return 1;
        }
        return n * jiecheng(n - 1);
    }
}

